@file:Suppress("unused")

package org.dromara.common.core.utils

import kotlin.math.min

fun <T, R, U> ((T) -> R).andThen(next: (R) -> U): (T) -> U = { input ->
    next(this(input))
}

fun CharSequence?.hasText(): Boolean = !isNullOrBlank()

fun String.sub(start: Int = 0, length: Int)  = this.substring(start, min((start + length), this.length))

fun <C> C?.ifNull(defaultValue: () -> C): C = this ?: defaultValue()

inline fun <C : Collection<*>> C?.ifNullOrEmpty(defaultValue: () -> C) =
    if (this.isNullOrEmpty()) defaultValue() else this
